package com.fjrz.bbxwj.main.notice.adapter

import android.widget.ImageView
import com.blankj.utilcode.util.ConvertUtils
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.fjrz.bbxwj.R
import com.fjrz.bbxwj.entity.*
import com.module.lemlin.base.loadCircleImage
import com.module.lemlin.base.loadRoundImage

class MessageBulletinAdapter :
    BaseQuickAdapter<Announcement, BaseViewHolder>(R.layout.item_message_bulletin) {

    init {
        addChildClickViewIds(R.id.tvMessageBulletinDetails)
    }

    override fun convert(holder: BaseViewHolder, item: Announcement) {
        holder.setText(R.id.tvMessageBulletinTime, TimeUtils.millis2String(item.createtime * 1000))
            .setText(R.id.tvMessageBulletinContent, item.content)
    }
}


class MessageSystemAdapter :
    BaseQuickAdapter<MessageSystem, BaseViewHolder>(R.layout.item_message_system) {

    init {
        addChildClickViewIds(R.id.tvMessageSystemDetails)
    }

    override fun convert(holder: BaseViewHolder, item: MessageSystem) {
        holder.setText(R.id.tvMessageSystemTime, TimeUtils.millis2String(item.createtime * 1000))
            .setText(R.id.tvMessageSystemContent, item.content)
    }
}

class MessageLikeAdapter :
    BaseQuickAdapter<MessageLike, BaseViewHolder>(R.layout.item_message_mutual) {
    override fun convert(holder: BaseViewHolder, item: MessageLike) {
        holder.setText(R.id.tvMessageMutualName, item.operate_user.nickname)
            .setText(
                R.id.tvMessageMutualTime,
                TimeUtils.millis2String(item.createtime * 1000, "MM-dd HH:mm")
            )
            .setText(R.id.tvMessageMutualContent, if (item.type == 1) "赞了你的视频" else "赞了你的评论")
            .getView<ImageView>(R.id.ivMessageMutualAvatar)
            .loadCircleImage(item.operate_user.avatar)
        holder.getView<ImageView>(R.id.ivMessageMutualImage)
            .loadRoundImage(item.video.main_image ?: "", ConvertUtils.dp2px(10f))
    }
}

class MessageCommentAdapter :
    BaseQuickAdapter<MessageComment, BaseViewHolder>(R.layout.item_message_mutual) {
    override fun convert(holder: BaseViewHolder, item: MessageComment) {
        holder.setText(R.id.tvMessageMutualName, item.user.nickname)
            .setText(
                R.id.tvMessageMutualTime,
                TimeUtils.millis2String(item.createtime * 1000, "MM-dd HH:mm")
            )
            .setText(R.id.tvMessageMutualContent, "发表评论：${item.content}")
            .getView<ImageView>(R.id.ivMessageMutualAvatar)
            .loadCircleImage(item.user.avatar)
        holder.getView<ImageView>(R.id.ivMessageMutualImage)
            .loadRoundImage(item.video.main_image ?: "", ConvertUtils.dp2px(10f))
    }
}

class MessageReplyAdapter :
    BaseQuickAdapter<MessageReply, BaseViewHolder>(R.layout.item_message_mutual) {
    override fun convert(holder: BaseViewHolder, item: MessageReply) {

        holder.setText(R.id.tvMessageMutualName, item.user.nickname)
            .setText(
                R.id.tvMessageMutualTime,
                TimeUtils.millis2String(item.createtime * 1000, "MM-dd HH:mm")
            )
            .setText(R.id.tvMessageMutualContent, "回复：${item.content}")
            .getView<ImageView>(R.id.ivMessageMutualAvatar)
            .loadCircleImage(item.user.avatar)
        holder.getView<ImageView>(R.id.ivMessageMutualImage)
            .loadRoundImage(item.video.main_image ?: "", ConvertUtils.dp2px(10f))
    }
}

class MessageChatAdapter :
    BaseQuickAdapter<ChatIndex, BaseViewHolder>(R.layout.item_message_chat) {
    override fun convert(holder: BaseViewHolder, item: ChatIndex) {

        holder.setText(R.id.tvMessageChatName, item.object_user.nickname)
            .setText(
                R.id.tvMessageChatTime,
                TimeUtils.millis2String(item.latest_message.createtime * 1000, "MM-dd HH:mm")
            )
            .setText(R.id.tvMessageChatContent, item.latest_message.content)
            .setText(R.id.tvMessageChatUnRead,item.unread.toString())
            .setGone(R.id.tvMessageChatUnRead,item.unread == 0)
            .getView<ImageView>(R.id.ivMessageChatAvatar)
            .loadCircleImage(item.object_user.avatar)
    }
}

class ChatListAdapter :
    BaseMultiItemQuickAdapter<ChatList, BaseViewHolder>() {

    init {
        addItemType(ChatList.SEND, R.layout.item_chat_send)
        addItemType(ChatList.RECEIVE, R.layout.item_chat_receive)
    }

    override fun convert(holder: BaseViewHolder, item: ChatList) {
        when (holder.itemViewType) {
            ChatList.SEND -> {
                holder.setText(R.id.tvChatSendContent, item.content)
                    .getView<ImageView>(R.id.ivChatSendAvatar).loadCircleImage(item.user.avatar)
            }
            ChatList.RECEIVE -> {
                holder.setText(R.id.tvChatReceiveContent, item.content)
                    .getView<ImageView>(R.id.ivChatReceiveAvatar).loadCircleImage(item.user.avatar)
            }
        }
    }
}

class ChatEmojiAdapter :
    BaseQuickAdapter<Int, BaseViewHolder>(R.layout.item_chat_emoji) {
    override fun convert(holder: BaseViewHolder, item: Int) {
        holder.setText(R.id.tvChatEmoji, String(Character.toChars(item)))
    }
}